/* Janus Chat - Version 1.0
 * Authors: Matthew Perry
 *          Michael Freid
 *          Marc Latou
 *          Richard Lee
 *
 * The Janus Chat Client is a highly secured
 * peer-to-peer chat client designed to facilitate
 * the transfer of sensitive data or as a communication
 * medium for the extra paranoid
 *
 * This file contains the unit tests for the message class*/



#include <string>
#include <iostream>
#include "../lib/message.h"
#include "../lib/jRsa.h"
#include "../lib/user.h"


int main(){

    //hardcoded tests
    try
    {
        //Something that throws an exception
        Message m("7840598720495702894750kjal;ksdjf;lkajsd;lfkja;dfjk;lkajdf;lkja;kdlfhlkhflkajhdljahd",83);//use the generic constructor
    }
    catch( BaseException* e )
    {
        //code that handles exception
        std::cout << "Error: " << e->what() << std::endl;
        std::cout << "The type, moniker and body of message m are as follows (separated by commas):" <<m.getType()<<","<<m.getMoniker<<","<<m.getBody()<<std::endl;
    }

    try
    {
        //Something that throws an exception
        Message m2("7840598720495702894750kjal;ksdjf;lkajsd;lfkja;dfjk;lkajdf;lkja;kdlfhlkhflkajhdljahd",32);//use the generic constructor but give it the wrong size
    }
    catch( BaseException* e )
    {
        //code that handles exception
        std::cout << "Error: " << e->what() << std::endl;
        std::cout << "The type, moniker and body of message m are as follows (separated by commas):" <<m2.getType()<<","<<m2.getMoniker<<","<<m2.getBody()<<std::endl;
    }

    try
    {
        //Something that throws an exception
        Message n(34, "Bob", "How's it going?"); //use an invalid message number (high)
    }
    catch( BaseException* e )
    {
        //code that handles exception
        std::cout << "Error: " << e->what() << std::endl;
        std::cout << "The type, moniker and body of message m are as follows (separated by commas):" <<n.getType()<<","<<n.getMoniker<<","<<n.getBody()<<std::endl;
    }
    try
    {
        //Something that throws an exception
        Message o(-4, "Billy", "check."); //use an invalid message number (low)
    }
    catch( BaseException* e )
    {
        //code that handles exception
        std::cout << "Error: " << e->what() << std::endl;
        std::cout << "The type, moniker and body of message m are as follows (separated by commas):" <<o.getType()<<","<<o.getMoniker<<","<<o.getBody()<<std::endl;
    }

    try
    {
        //Something that throws an exception (possibly)
        Message p(2, "Sam", "I got ur message."); //use a message that should work
    }
    catch( BaseException* e )
    {
        //code that handles exception
        std::cout << "Error: " << e->what() << std::endl;
        std::cout << "The type, moniker and body of message m are as follows (separated by commas):" <<p.getType()<<","<<p.getMoniker<<","<<p.getBody()<<std::endl;
    }

    try
    {
        //Something that throws an exception
        Message q(3, "jlkjljlkjoiljlkjlkjslkjfkl;jkkadlfkjiolkljiiouerf", "That's a long name!");  //use a moniker that is too long
    }
    catch( BaseException* e )
    {
        //code that handles exception
        std::cout << "Error: " << e->what() << std::endl;
        std::cout << "The type, moniker and body of message m are as follows (separated by commas):" <<q.getType()<<","<<q.getMoniker<<","<<q.getBody()<<std::endl;
    }

    try
    {
        //Something that throws an exception
        Message copp(p); //try out the copy constructor
    }
    catch( BaseException* e )
    {
        //code that handles exception
        std::cout << "Error: " << e->what() << std::endl;
        std::cout << "The type, moniker and body of message m are as follows (separated by commas):" <<copp.getType()<<","<<copp.getMoniker<<","<<copp.getBody()<<std::endl;
    }

    //make a public and private key to test encryption functionality
    User sammy();

    try
    {
        //Something that throws an exception
        copp.toEncrypt( sammy.getPublicKey( ) );  //try to encrypt my message
    }
    catch( BaseException* e )
    {
        //code that handles exception
        std::cout << "Error: " << e->what() << std::endl;
        std::cout << "The type, moniker and body of message m are as follows (separated by commas):" <<copp.getType()<<","<<copp.getMoniker<<","<<copp.getBody()<<std::endl;
    }

    try
    {
        //Something that throws an exception
        Message r(3, "Bob", " ");  //is this too short?
        r.toEncrypt( sammy.getPublicKey( ) );  //try to encrypt my message (is this too small to encrypt?)
    }
    catch( BaseException* e )
    {
        //code that handles exception
        std::cout << "Error: " << e->what() << std::endl;
        std::cout << "The type, moniker and body of message m are as follows (separated by commas):" <<r.getType()<<","<<r.getMoniker<<","<<r.getBody()<<std::endl;
    }

    try
    {
        //Something that throws an exception
        copp.toDecrypt( sammy.getPrivateKey( ) );  //try to decrypt this message
    }
    catch( BaseException* e )
    {
        //code that handles exception
        std::cout << "Error: " << e->what() << std::endl;
        std::cout << "The type, moniker and body of message m are as follows (separated by commas):" <<copp.getType()<<","<<copp.getMoniker<<","<<copp.getBody()<<std::endl;
    }


return 0;
}
